import {
    Controller,
    Get,
    Post,
    Body,
    Patch,
    Param,
    Delete,
    Request,
    Query,
    UseGuards,
    UseInterceptors, Req,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ApiAuthGuard } from '@/guard/api-auth.guard';
import { LogInterceptor } from '@/interceptors/log.inerceptor';


@ApiTags('用户相关')
@ApiBearerAuth()
@Controller('system/user')
export class UserController {
    constructor(private readonly userService: UserService) {
    }
    
    @Post()
    @UseGuards(ApiAuthGuard)
    @ApiOperation({ summary: '创建用户' })
    create(@Body() createUserDto: CreateUserDto, @Request() req) {
        return this.userService.create(createUserDto, req?.user.id);
    }
    
    @Get('getUserMenu')
    @ApiOperation({ summary: '查询用户菜单' })
    getUserMenu(@Request() req) {
        return this.userService.getUserMenu(req.user.id);
    }
    
    @Get('findAllNoPage')
    @ApiOperation({ summary: '获取用户列表-不分页' })
    @UseGuards(ApiAuthGuard)
    findAllNoPage(@Query() dto) {
        return this.userService.findAllNoPage(dto);
    }
    
    @Get()
    @UseGuards(ApiAuthGuard)
    @ApiOperation({ summary: '获取用户列表' })
    findAll(@Query() dto) {
        return this.userService.findAll(dto);
    }
    
    @Get('findChildAll')
    @UseGuards(ApiAuthGuard)
    @ApiOperation({ summary: '获取child用户列表' })
    findChildAll(@Req() req) {
        return this.userService.findChildAll(req?.user.id);
    }
    
    @Get('findChildAllPage')
    @UseGuards(ApiAuthGuard)
    @ApiOperation({ summary: '获取child用户列表-分页' })
    findChildAllPage(@Req() req) {
        return this.userService.findChildAllPage({
            userId: req?.user.id,
        });
    }
    
    
    @Patch(':id')
    @UseGuards(ApiAuthGuard)
    @UseInterceptors(LogInterceptor)
    @ApiOperation({ summary: '修改' })
    update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
        return this.userService.update(+id, updateUserDto);
    }
    
    @Delete(':id')
    @UseGuards(ApiAuthGuard)
    @ApiOperation({ summary: '删除' })
    remove(@Param('id') id: string) {
        return this.userService.remove(+id);
    }
    
    @Get('info')
    @ApiOperation({ summary: '查询用户信息' })
    info(@Request() req) {
        return this.userService.info(req.user.id);
    }
    
    
}

